package com.cango.student;

import com.alibaba.fastjson.JSONObject;
import com.google.common.io.Files;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: student
 * @description:
 * @author: xie jiefeng
 * @create: 2019-05-20 18:05
 */
@Slf4j
public class CouponReceive {

    public static void main(String[] args) throws Exception {
//        List<String> list = fileNio();
//
//        for (String info : list) {
//            System.out.println(info);
//        }

        List<String> list = new ArrayList<>();
        list.add("14219357967214653400091");
        list.add("14221433934310227700065");
        list.add("14223739548968634900066");
        list.add("14228537405044866700048");
        list.add("14247390705789877100091");
        list.add("14257434464267188900017");
        list.add("14258646139553113200076");
        RestTemplate restTemplate = new RestTemplate();

        String url = "http://172.81.229.73/PayV2/ebuytraderefund?appid=cocogroup";

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");

        for (String info : list) {
            JSONObject object = new JSONObject();
            object.put("out_trade_no", info);
            HttpEntity<String> formEntity = new HttpEntity<>(JSONObject.toJSONString(object), headers);
            try {
                ResponseEntity<String> entity = restTemplate.postForEntity(url, formEntity, String.class, new Object());
                System.out.println(entity.getBody());
            } catch (Exception ex) {
                log.error("退款失败", ex);
            }


        }

    }

//    public static void main(String[] args) throws Exception {
//        List<String> list = fileNio();
//
//        for (String info : list) {
//            System.out.println(info);
//        }
//        RestTemplate restTemplate = new RestTemplate();
//
//        String url = "http://172.81.229.73/PayV2/ebuytraderefund?appid=cocogroup";
//
//        HttpHeaders headers = new HttpHeaders();
//        headers.add("Content-Type", "application/json");
//
////        for (String info : list) {
//            JSONObject object = new JSONObject();
//            object.put("out_trade_no", "14228610774417488600071");
//            HttpEntity<String> formEntity = new HttpEntity<>(JSONObject.toJSONString(object), headers);
//            ResponseEntity<String> entity = restTemplate.postForEntity(url, formEntity, String.class, new Object());
//
//            System.out.println(entity.getBody());
//
////        }
//
//    }

    /**
     * 读取文件内容
     *
     * @throws Exception
     */
    public static List<String> fileNio() throws Exception {
        File file = new File("/Users/xiejiefeng/work/退款订单");
        try {
            List<String> list = Files.readLines(file, Charset.forName("UTF-8"));
            return list;
        } catch (IOException e) {

        }
        return null;
    }
}
